package com.raymond.entity.commons;

import lombok.Data;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * desc-公共汇总对象
 *
 * @author houmenghe
 * @date 2025/04/21 17:32
 **/
@Data
@ToString
public class SummaryResponse<T> extends PageResponse<T> {
    /**
     * 汇总信息
     */
    private Map<String, Long> summary;

    private Map<String, BigDecimal> decimalSummary;

    /**
     * 存放额外参数
     * @param key key
     * @param value value
     */
    public void put(String key, Long value) {
        if (summary == null) {
            summary = new HashMap<>();
        }
        summary.put(key, value);
    }

    /**
     * 创建分页 response 实体
     *
     * @param pageRequest 分页参数
     * @return response
     * @param <T> 泛型
     */
    public static <T> SummaryResponse<T> create(PageRequest pageRequest) {
        SummaryResponse<T> pageResponse = new SummaryResponse<>();
        pageResponse.setPageNo(pageRequest.getPageNo());
        pageResponse.setPageSize(pageRequest.getPageSize() == null ? 10 : pageRequest.getPageSize());
        return pageResponse;
    }
}
